package com.ruicar.afs.cloud.manage.revoke.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.manage.common.entity.ManageRevokeHandle;
import com.ruicar.afs.cloud.manage.common.service.ManageRevokeHandleService;
import com.ruicar.afs.cloud.manage.revoke.condition.ManageCollectCancelCondition;
import com.ruicar.afs.cloud.manage.revoke.vo.ManageRevokeHandleVo;
import com.ruicar.afs.cloud.manage.workflow.processor.ApproveTaskProcessor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/8/7 14:46
 */
@Slf4j
@RestController
@Api("撤销处理")
@RequestMapping("/revokeHandle")
@AllArgsConstructor
public class ManageRevokeHandleController {
    private final ManageRevokeHandleService manageRevokeHandleService;
    private final ApproveTaskProcessor approveTaskProcessor;

    @PostMapping(value = "/revokedStartProcess")
    @ApiOperation(value = "发起流程")
    public IResponse revokedStartProcess(@RequestBody ManageRevokeHandleVo vo) {
        return IResponse.success(manageRevokeHandleService.revokedHandleStartProcess(vo));
    }

    @PostMapping(value = "/revokeSubmitProcess")
    @ApiOperation(value = "提交流程")
    public IResponse revokeSubmitProcess(@RequestBody ManageRevokeHandleVo vo) {
        return IResponse.success(manageRevokeHandleService.revokeHandleSubmitProcess(vo));
    }
    @PostMapping(value = "/getManageRevokeHandle")
    @ApiOperation(value = "获取撤销处理数据")
    public IResponse getManageRevokeHandle(@RequestParam("caseNo") String caseNo) {
        ManageRevokeHandle manageRevokeHandle=manageRevokeHandleService.getOne(Wrappers.<ManageRevokeHandle>query().lambda()
                .eq(ManageRevokeHandle::getCaseNo,caseNo));
        return IResponse.success(manageRevokeHandle);
    }
    @PostMapping(value = "/getManageRevokeHandleList")
    @ApiOperation(value = "获取撤销处理数据")
    public IResponse getManageRevokeHandleList(@RequestBody ManageCollectCancelCondition vo) {
        IPage page = manageRevokeHandleService.getManageHandleList(new Page(vo.getPageNumber(), vo.getPageSize()),vo);
        page.setRecords(approveTaskProcessor.handle(page.getRecords()));
        return IResponse.success(page);
    }

}
